/**
 * Copyright 2010 Creative Works, Inc.
 * Creative Works licenses this file to you under the Apache License, version
 * 2.0 (the "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.  See the License for the specific language governing
 * permissions and limitations under the License.
 */
package org.sendvox.freswitch.inbound.impl;

public enum ResponseCallbacks {

	/**
	 * Content-Type
	 */
	CONTENT_TYPE("Content-Type"),
	/**
	 * Content-Length is the length of the event beginning AFTER the double LF
	 * line ("\n\n") of the event header
	 */
	CONTENT_LENGTH("Content-Length"),

	/**
	 * Reply-Text returns the server's response; might contain "+OK [Success
	 * Message]" on success or "-ERR [Error Message]" on failure
	 */
	REPLY_TEXT("Reply-Text"),
	/**
	 * Job-UUID an immutable universally unique identifier (UUID). A UUID
	 * represents a 128-bit value.The BACKGROUND_JOB event will contain a
	 * Job-UUID that matches up with Job-UUID returned by the server when bgapi
	 * is called.
	 */
	JOB_UUID("Job-UUID"),
	/**
	 * Socket-Mode sync or async
	 */
	SOCKET_MODE("Socket-Mode"), ;

	private final String name;

	private ResponseCallbacks(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public static ResponseCallbacks fromLiteral(String literal) {
		for (ResponseCallbacks header : values()) {
			if (header.name.equalsIgnoreCase(literal)) {
				return header;
			}
		}
		return null;
	}

	public static enum Value {
		OK("+OK accepted"), 
		AUTH_REQUEST("auth/request"), 
		API_RESPONSE("api/response"), 
		COMMAND_REPLY("command/reply"), 
		TEXT_EVENT_PLAIN("text/event-plain"), 
		TEXT_EVENT_XML("text/event-xml"), 
		TEXT_DISCONNECT_NOTICE("text/disconnect-notice"), 
		ERR_INVALID("-ERR invalid");

		private final String literal;

		private Value(String literal) {
			this.literal = literal;
		}

		public String getLiteral() {
			return literal;
		}

		public static Value fromLiteral(String literal) {
			for (Value header : values()) {
				if (header.literal.equalsIgnoreCase(literal)) {
					return header;
				}
			}
			return null;
		}

	}
}
